import time, threading, random, Queue, wx
class GuiPart(wx.App):
    def __init__(self, queue, master):
        wx.App.__init__(self, redirect=True)
        self.queue = queue
        self.master = master
        self.initGUI()    
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.processIncoming, self.timer)
        self.timer.Start(200)
        
    def initGUI(self):
        self.frame = wx.Frame(None)
        self.frame.Show()
        self.button = wx.Button(self.frame,label="Stop")
        self.button.Bind(wx.EVT_BUTTON, self.OnPress, self.button)
        #self.button.Show()
    
    def OnPress(self, evt):
        dlg = wx.MessageDialog( self.frame, "are you sure you want to do that?", "About Sample Editor", wx.OK)
        dlg.ShowModal()
        dlg.Destroy()
        self.master.endApplication()
    
    def processIncoming(self, hji):
        while self.queue.qsize( ):
            msg = self.queue.get(0)
            print "hello: " + str(msg)
            
class ThreadedClient(object):
    def __init__(self):
        self.queue = Queue.Queue( ) 
        self.gui = GuiPart(self.queue, self)
        self.running = True
        self.thread1 = threading.Thread(target=self.workerThread1)
        self.thread1.start( )
        self.gui.MainLoop()
        
    def workerThread1(self):
        while self.running:
            time.sleep(rand.random( ) * 1.5)
            msg = rand.random( )
            self.queue.put(msg)
            
    def endApplication(self):
        self.running = False

rand = random.Random( )
tc = ThreadedClient()